package cn.usaiot.server;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//


import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.Bitmap.Config;
import java.nio.ByteBuffer;

public abstract class Frame {
    protected COLOR_FORMAT colorFormat;
    protected Bitmap bitmap;
    private ROTATE rotate;

    public Frame() {
    }

    public static void a(PointF[] var0, int var1, int var2, ROTATE var3) {
        byte var6 = 0;
        int var5 = 0;
        byte var7 = 0;
        if (var0 == null) {
            throw new NullPointerException("points array must not be null");
        } else {
            int var8 = var1 - 1;
            int var9 = var2 - 1;
            var1 = var7;
            var2 = var6;
            float var4;
            PointF var10;
            switch(var3) {
                case c:
                    while(var1 < var0.length) {
                        var10 = var0[var1];
                        var4 = var10.x;
                        var10.x = var10.y;
                        var10.y = (float)var9 - var4;
                        var0[var1] = var10;
                        ++var1;
                    }

                    return;
                case b:
                    while(var2 < var0.length) {
                        var10 = var0[var2];
                        var10.x = (float)var8 - var10.x;
                        var10.y = (float)var9 - var10.y;
                        var0[var2] = var10;
                        ++var2;
                    }

                    return;
                case a:
                    while(var5 < var0.length) {
                        var10 = var0[var5];
                        var4 = var10.x;
                        var10.x = (float)var8 - var10.y;
                        var10.y = var4;
                        var0[var5] = var10;
                        ++var5;
                    }
            }

        }
    }

    public Bitmap getBitmap() {
        return this.bitmap;
    }

    public void setTargetRotation(ROTATE var1) {
        if (var1 == null) {
            throw new NullPointerException("target rotation must not be null");
        } else {
            this.rotate = var1;
        }
    }

    public abstract int getWidth();

    public abstract int getHeight();

    public int length() {
        return getWidth() * getHeight();
    }

    public COLOR_FORMAT getColorFormat() {
        return this.colorFormat;
    }

    public ROTATE getTargetRotation() {
        return this.rotate;
    }

    public static class BitmapFrame extends Frame {
        //private Bitmap bitmap;

        public int getWidth() {
            return bitmap.getWidth();
        }

        public int getHeight() {
            return bitmap.getHeight();
        }

        public Bitmap getBitmap() {
            return this.bitmap;
        }

        public ByteArrayFrame getByteArrayFrame() {
            ByteBuffer var1 = ByteBuffer.allocate(this.bitmap.getByteCount());
            bitmap.copyPixelsToBuffer(var1);
            byte[] var2 = var1.array();
            if (this.colorFormat == COLOR_FORMAT.RGBA && this.bitmap.getConfig() != Config.ARGB_8888) {
                throw new IllegalArgumentException(String.format("Unsupported Bitmap.Config for BGR frame. Expecting Bitmap.Config.ARGB_8888."));
            } else {
                ByteArrayFrame var3 = new ByteArrayFrame(var2, getWidth(), getHeight(), getColorFormat());
                var3.setTargetRotation(getTargetRotation());
                var3.bitmap = this.bitmap;
                return var3;
            }
        }
    }

    public static class ByteArrayFrame extends Frame {
        private byte[] byteArray;
        private int width;
        private int height;

        public ByteArrayFrame(byte[] var1, int var2, int var3, COLOR_FORMAT var4) {
            if (var1 == null) {
                throw new NullPointerException("byte array must not be null");
            } else if (var4 == null) {
                throw new NullPointerException("frame color format must not be null");
            } else {
                byteArray = var1;
                width = var2;
                height = var3;
                colorFormat = var4;
                //length();
                if (colorFormat == COLOR_FORMAT.RGBA && byteArray.length < width*height * 4) {
                    throw new IllegalArgumentException(String.format("Length of data must be == width*height*4 (%d*%d)", width, height));
                } else if (colorFormat == COLOR_FORMAT.YUV_NV21 && byteArray.length < width *height* 3 / 2) {
                    throw new IllegalArgumentException(String.format("Length of yuv data must be == w*h*3/2 (%d*%d)", width, height));
                } else {
                    this.setTargetRotation(ROTATE.d);
                }
            }
        }

        public int getWidth() {
            return width;
        }

        public int getHeight() {
            return height;
        }

        public byte[] getByteArray() {
            return byteArray;
        }
    }

    public enum COLOR_FORMAT {
//        a,
//        b,
//        c;
        RGBA,
        YUV_NV21,
        UNKNOWN_TYPE
    }

    public enum ROTATE {
        a(90.0D),
        b(180.0D),
        c(-90.0D),
        d(0.0D);

        private double e;

        ROTATE(double var3) {
            this.e = var3;
        }

        public double toDouble() {
            return this.e;
        }
    }
}
